package com.heart.serviceribbon;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * 服务测试
 *
 * @author: heart
 * @date: 2018/6/15
 */
@Service
public class HelloService {

    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "helloError")
    public String hello(String name, String method) {
        return restTemplate.getForObject("http://eureka-client/home?name=" + name + "&method=" + method, String.class);
    }

    /**
     * fallback函数，入参和返回类型需要一致
     * 
     * @param name
     * @param method
     * @return
     */
    private String helloError(String name, String method) {
        return "hello " + name + ",there is some errors!";
    }

}
